using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;

namespace SubManager.Win
{
    public partial class PopupForm : Form
    {
        public PopupForm()
        {
            InitializeComponent();
        }

        public PopupForm(UserControl uc) : this()
        {
            if ((uc != null) && (uc is IEntityUC))
            {
                Controls.Add(uc);

                Height = uc.Height + 35;
                Width = uc.Width + 20;

                uc.Location = new Point(7, 10);

                (uc as IEntityUC).OK += new MyHandle(PopupForm_OK);
                (uc as IEntityUC).Cancel += new MyHandle(PopupForm_Cancel);
            }
        }

        void PopupForm_Cancel()
        {
            DialogResult = DialogResult.Cancel;
        }

        void PopupForm_OK()
        {
            DialogResult = DialogResult.OK;
        }

        private void PopupForm_KeyDown(object sender, KeyEventArgs e)
        {
            if (e.KeyCode.Equals(Keys.Escape))
            {
                DialogResult = DialogResult.Cancel;
                Close();
            }
        }
    }
}